//  书写品牌管理模块的接口
import request from '@/utils/request'
import type { PageInstanceVO, Response } from '@/api/type'
import { TrademarkDTO, TrademarkVO } from './type'

enum API {
  //  获取品牌列表
  TRADEMARK_URL = '/admin/product/baseTrademark/list',
  //  添加品牌
  ADD_TRADEMARK_URL = '/admin/product/baseTrademark/save',
  //  删除品牌
  DELETE_TRADEMARK_URL = '/admin/product/baseTrademark/remove',
  //  更新品牌
  UPDATE_TRADEMARK_URL = '/admin/product/baseTrademark/update'
}

//  获取品牌列表(restful 风格)
export const queryTrademarkList = async (page: number, limit: number) => request.get<any, Response<PageInstanceVO<TrademarkVO>>>(`${API.TRADEMARK_URL}/${page}/${limit}`)

//  添加品牌
export const saveOrUpdateTrademark = async (data: TrademarkDTO) => {
  if (data.id) {
    console.log('id存在')
    return request.put<any, Response<void>>(API.UPDATE_TRADEMARK_URL, data)
  }
  return request.post<any, Response<void>>(API.ADD_TRADEMARK_URL, data)
}

// 删除品牌
export const deleteTrademarkById = async (id: number) => request.delete<any, Response<void>>(`${API.DELETE_TRADEMARK_URL}/${id}`)